Page({
    data: {
        time: '12:30',
        dressId: '',
        dress: null,
        // 礼服数据示例
        dressExample: {
            id: 1,
            name: '法式蕾丝鱼尾婚纱',
            code: 'WD2401',
            color: '象牙白',
            price: '18,800',
            size: '定制',
            material: '法国进口蕾丝、缎面',
            description: '优雅的鱼尾剪裁，搭配精美法国蕾丝和精致珠片，彰显新娘高贵气质。',
            status: '可用',
            rentalPrice: '12,800',
            depositPrice: '5,000',
            designer: 'Marie Claire',
            style: '法式浪漫',
            tags: ['新款', '热门', '鱼尾'],
            mainImage: 'https://images.unsplash.com/photo-1594612658290-386d64b8dd1c?ixlib=rb-4.0.3&auto=format&fit=crop&w=300&q=80',
            images: [
                'https://images.unsplash.com/photo-1594612658290-386d64b8dd1c?ixlib=rb-4.0.3&auto=format&fit=crop&w=300&q=80',
                'https://images.unsplash.com/photo-1596444382656-f81a489d9190?ixlib=rb-4.0.3&auto=format&fit=crop&w=300&q=80',
                'https://images.unsplash.com/photo-1585241920473-cb2a0ff38d8b?ixlib=rb-4.0.3&auto=format&fit=crop&w=300&q=80'
            ],
            sizeChart: {
                bust: '84cm',
                waist: '60cm',
                hips: '90cm',
                height: '165cm'
            },
            schedule: [
                { 
                    date: '2024-03-22', 
                    clientName: '周小姐',
                    type: 'pickup',
                    status: '已确认'
                },
                { 
                    date: '2024-03-28', 
                    clientName: '陈小姐',
                    type: 'try',
                    status: '待确认'
                }
            ]
        }
    },

    onLoad(options) {
        // 更新当前时间
        this.updateTime();
        this.getTimerID = setInterval(this.updateTime, 60000);
        
        // 获取礼服ID
        if (options.id) {
            this.setData({
                dressId: options.id
            });
            
            // 根据ID获取礼服详情
            this.fetchDressDetail(options.id);
        }
    },

    onUnload() {
        clearInterval(this.getTimerID);
    },

    updateTime: function() {
        const date = new Date();
        const hours = date.getHours();
        const minutes = date.getMinutes();
        this.setData({
            time: `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}`
        });
    },

    // 获取礼服详情
    fetchDressDetail: function(dressId) {
        // 这里应该是API请求，目前使用模拟数据
        wx.showLoading({
            title: '加载中...',
        });
        
        // 模拟API请求延迟
        setTimeout(() => {
            // 使用示例数据
            this.setData({
                dress: this.data.dressExample
            });
            wx.hideLoading();
            // 真实项目中这里会有实际的API调用
        }, 500);
    },

    // 返回上一页
    navigateBack: function() {
        wx.navigateBack();
    },

    // 预览图片
    previewImage: function(e) {
        const { images } = this.data.dress;
        const current = e.currentTarget.dataset.src;
        
        wx.previewImage({
            current,
            urls: images
        });
    },

    // 查看档期
    viewSchedule: function() {
        const { code } = this.data.dress;
        wx.navigateTo({
            url: `/pages/dress_calendar/dress_calendar?dressCode=${code}`
        });
    },

    // 编辑礼服
    editDress: function() {
        const { id } = this.data.dress;
        wx.navigateTo({
            url: `/pages/dress_edit/dress_edit?id=${id}`
        });
    },

    // 创建订单
    createOrder: function() {
        const { id } = this.data.dress;
        wx.navigateTo({
            url: `/pages/create_order/create_order?dressId=${id}`
        });
    }
}) 